$(function () {
	
	$.ajax({
        url: severUrl+'index.php?m=Web&a=newsroom',
        type: 'GET',
        dataType: 'JSONP'
    })
    .done(function(data) {
        console.log("success");
        console.log(data);
        announcementsFun(data.announcements);
        feature_newsFun(data.feature_news);
        photosFun(data.photos);
        
    })
    .fail(function() {
        console.log("error");
    })
    .always(function() {
        console.log("complete");
    });


    // announcements
	function announcementsFun(data){
	    var dari = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
	    var ANNList = $('#ANNList');
	    var html = '';

	    for (var i = 0; i < data.length; i++) {
	        var issueDate = data[i].issueDate
	        var nian = (issueDate.split("-"))[0];
	        var yue = (issueDate.split("-"))[1];
	        var ri = (issueDate.split("-"))[2];


	        var cn = '<li class="clearfloat">'+
	        ' <div class="timeCom">'+dari[(yue-1)] +' '+ri+', '+nian+'</div>'+
	        '<div class="RigCon">'+
	        '<a href="article.html?article_id='+data[i].article_id+'">'+
	        '<p>'+data[i].title+'</p>'+
	        '<span>PRESS RELEASE</span>'+
	        '</a>'+
	        '</div>'+
	        '</li>';
	        html+=cn;
	    }
	    ANNList.html(html);
	}
	// announcements end



	// feature_news
	function feature_newsFun(data){
	   var FeaturelsCn = $('#FeaturelsCn');
	   var html = '';

	   for (var i = 0; i < data.length; i++) {

	   	html+= '<li><a href="article.html?article_id='+data[i].article_id+'" class="clearfloat"><div class="imgC"><img src="'+data[i].image_url+'"></div><div class="word"><div class="head">'+data[i].title+'</div><p>'+data[i].seo_description+'</p></div></a></li>';
	      
		}
		FeaturelsCn.html(html);
		}





function photosFun(data){
   var photosCon = $('#photosCon');
   var html = '';

   var dateind = [];

   for (var i = 0; i < data.length; i++) {
   	dateind.push(data[i].image_url);
      html += '<div class="swiper-slide"><a href="javascript:void(0);"><img  data-in="'+(i+1)+'" src="'+data[i].image_url+'"></a></div>'

   }

   photosCon.html(html);


   function photosSwiper(){
	   	 var photosSwiper = new Swiper ('.photosSwiper', {
	        direction : 'horizontal',
	        slidesPerView : 'auto'
	    }) 
   }
   photosSwiper();

   photosCon.on('click', 'img', function(event) {
   	     var dataIn = $(this).attr('data-in');

   	     PhotoPreviewFun(dateind,dataIn-1);

   	
   });

      
}

})